| Conditions | 1 |
| Paths | 1 |
| Total Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 33 | .directive('credentialField', ['$timeout', '$translate', function ($timeout, $translate) { |
||
| 34 | return { |
||
| 35 | scope: { |
||
| 36 | value: '=value', |
||
| 37 | secret: '=secret', |
||
| 38 | inputField: '=useInput', |
||
| 39 | inputFieldplaceholder: '=inputPlaceholder' |
||
| 40 | }, |
||
| 41 | restrict: 'A', |
||
| 42 | replace: 'true', |
||
| 43 | template: "" + |
||
| 44 | '<span class="credential_field">' + |
||
| 45 | '<div class="value" ng-class="{\'ellipsis\': isLink}">' + |
||
| 46 | '<span ng-if="secret"><span ng-repeat="n in [] | range:value.length" ng-if="!valueVisible">*</span></span>' + |
||
| 47 | '<span ng-if="valueVisible && !inputField" ng-bind-html="value"></span>' + |
||
| 48 | '<span ng-if="valueVisible && inputField"><input type="text" ng-model="value" select-on-click placeholder="{{ inputFieldplaceholder }}!"</span>' + |
||
| 49 | '</div>' + |
||
| 50 | '<div class="tools">' + |
||
| 51 | '<div class="cell" ng-if="toggle" tooltip="tggltxt" ng-click="toggleVisibility()"><i class="fa" ng-class="{\'fa-eye\': !valueVisible, \'fa-eye-slash\': valueVisible }"></i></div>' + |
||
| 52 | '<div class="cell" ng-if="isLink"><a ng-href="{{value}}" target="_blank" rel="nofollow noopener noreferrer"><i tooltip="\'Open in new window\'" class="link fa fa-external-link"></i></a></div>' + |
||
| 53 | '<div class="cell" ngclipboard-success="onSuccess(e);" ngclipboard-error="onError(e);" ngclipboard data-clipboard-text="{{value}}"><i tooltip="copy_msg" class="fa fa-clipboard"></i></div>' + |
||
| 54 | '</div></span>', |
||
| 55 | link: function (scope) { |
||
| 56 | var expression = /(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/gi; |
||
| 57 | var regex = new RegExp(expression); |
||
| 58 | $translate(['toggle.visibility', 'copy', 'copied']).then(function (translations) { |
||
| 59 | scope.tggltxt = translations['toggle.visibility']; |
||
| 60 | scope.copy_msg = translations['copy.field']; |
||
| 61 | }); |
||
| 62 | |||
| 63 | scope.$watch("value", function () { |
||
| 64 | if (scope.value) { |
||
| 65 | if (scope.secret) { |
||
| 66 | scope.valueVisible = false; |
||
| 67 | } |
||
| 68 | if (regex.test(scope.value)) { |
||
| 69 | scope.isLink = true; |
||
| 70 | if(scope.value.substr(0,4) !== 'http'){ |
||
| 71 | scope.value = 'http://'+scope.value; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | }); |
||
| 76 | if (!scope.toggle) { |
||
| 77 | if (scope.secret) { |
||
| 78 | scope.toggle = true; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | var timer; |
||
| 83 | scope.onSuccess = function () { |
||
| 84 | scope.copy_msg = $translate.instant('copied') ; |
||
| 85 | $timeout.cancel(timer); |
||
| 86 | timer = $timeout(function () { |
||
| 87 | scope.copy_msg = $translate.instant('copy'); |
||
| 88 | }, 5000); |
||
| 89 | }; |
||
| 90 | scope.valueVisible = true; |
||
| 91 | scope.toggleVisibility = function () { |
||
| 92 | scope.valueVisible = !scope.valueVisible; |
||
| 93 | }; |
||
| 94 | } |
||
| 95 | }; |
||
| 96 | }]); |
||
| 97 | |||
| 99 |